 /**
* 
* @图片上传
*/
function init_uploadlp(nameId,ul_pics){
 var data_type = $("#"+nameId).attr('data-type');
 var url = $("#"+nameId).attr('data-url');
 var name = $("#"+nameId).attr('data-name');
 var data_value = $("#"+nameId).attr('data-value');
 if(data_type == 1){
      var up_file = false;
 }else{
      var up_file = true;
      name = name+'[]';
 }
 template = '';
if( data_value != '' && data_value != undefined ) {
		data_value = data_value.split( ',' );
		$.each(data_value , function( k , v ){
			template +='<li style="width:auto;float:left;margin:0px 8px; padding:0px;border:1px solid #CCC;">';
			template += '<a href=\"javascript:;\" class=\"img_upload_close\" onclick=\"img_upload_close(this)\">×</a>';
			template +='<div class="img">';
			template +='<input type="hidden" name="'+name+'" value="' + v +'">';
			template +='<img style="width:100px;height:100px;" src="' + v +'">';
			template +='</div></li>';
		});
                 $("#"+ul_pics).html(template); 
	}
        
  var uploader = new plupload.Uploader({ //创建实例的构造方法 
      runtimes: 'html5,flash,silverlight,html4', 
      //上传插件初始化选用那种方式的优先级顺序 
      browse_button: nameId, 
      // 上传按钮 
      url: url, 
      //远程上传地址 
      flash_swf_url: 'plupload/Moxie.swf', 
      //flash文件地址 
      silverlight_xap_url: 'plupload/Moxie.xap', 
      //silverlight文件地址 
      filters: { 
          max_file_size: '500kb', 
          //最大上传文件大小（格式100b, 10kb, 10mb, 1gb） 
          mime_types: [ //允许文件上传类型 
          { 
              title: "files", 
              extensions: "jpg,png,gif" 
          }] 
      }, 
      multi_selection: up_file, 
      //true:ctrl多文件上传, false 单文件上传 
      init: { 
          FilesAdded: function(up, files) { //文件上传前 
              if ($("#"+ul_pics).children("li").length > 30) { 
                  alert("您上传的图片太多了！"); 
                  uploader.destroy(); 
              } else { 
                  var li = ''; 
                  plupload.each(files, 
                  function(file) { //遍历文件 
                      li += "<li id='" + file['id'] + "' style='width:auto;float:left;margin:0px 8px; padding:0px;border:1px solid #CCC;'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></li>"; 
                  }); 
                  if(up_file){
                      $("#"+ul_pics).append(li); 
                  }else{
                      $("#"+ul_pics).html(li); 
                  }
                  
                  uploader.start(); 
              } 
          }, 
          UploadProgress: function(up, file) { //上传中，显示进度条 
              $("#" + file.id).find('.bar').css({ 
                  "width": file.percent + "%" 
              }).find(".percent").text(file.percent + "%"); 
          }, 
          FileUploaded: function(up, file, info) { //文件上传成功的时候触发 
              var data = JSON.parse(info.response); 
                  $("#" + file.id).html("<a href=\"javascript:;\" class=\"img_upload_close\" onclick=\"img_upload_close(this)\">×</a><div class='img' ><input type='hidden' name='"+name+"' value='" + data.pic + "'/><img  style='width:100px;height:100px;' src='" + data.pic + "'/></div>" ); 
          }, 
          Error: function(up, err) { //上传出错的时候触发 
              alert(err.message); 
          } 
      } 
  }); 
    uploader.init();
}

function img_upload_close( obj ) {
	$(obj).parent().remove();
}
